package com.hskn.hss.module.tldictattentionclass.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hskn.hss.core.utils.LoginUtils;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tldictattentionclass.entity.TlEmergentDictAttentionClass;
import com.hskn.hss.module.tldictattentionclass.mapper.TlEmergentDictAttentionClassMapper;
import com.hskn.hss.module.tldictattentionclass.service.ITlEmergentDictAttentionClassService;
import com.hskn.hss.module.userdepart.entity.SysUserDepart;
import com.hskn.hss.module.userdepart.mapper.SysUserDepartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Service
public class TlEmergentDictAttentionClassServiceImpl extends ServiceImpl<TlEmergentDictAttentionClassMapper, TlEmergentDictAttentionClass> implements ITlEmergentDictAttentionClassService {

    @Resource
    TlEmergentDictAttentionClassMapper tlEmergentDictAttentionClassMapper;
    @Resource
    SysUserDepartMapper sysUserDepartMapper;

    @Override
    public AjaxResult insert(JSONObject params) throws HssException {

        String uid = LoginUtils.getUser().getUid();
        TlEmergentDictAttentionClass tlEmergentDictAttentionClass = params.getObject("data", TlEmergentDictAttentionClass.class);

        QueryWrapper<SysUserDepart> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUserDepart::getUserid, uid);
        String deptid = sysUserDepartMapper.selectOne(queryWrapper).getDepid();

        tlEmergentDictAttentionClass.setCreateby(uid);
        tlEmergentDictAttentionClass.setCreatetime(new Date());
        tlEmergentDictAttentionClass.setDeptid(deptid);
        if (tlEmergentDictAttentionClass.getStatus() == null || tlEmergentDictAttentionClass.getStatus().isEmpty()) {
            tlEmergentDictAttentionClass.setStatus("1");
        }
        tlEmergentDictAttentionClassMapper.insert(tlEmergentDictAttentionClass);
        return AjaxResult.success("操作成功");
    }

    @Override
    public AjaxResult update(JSONObject params) throws HssException {

        String uid = LoginUtils.getUser().getUid();
        TlEmergentDictAttentionClass tlEmergentDictAttentionClass = params.getObject("data", TlEmergentDictAttentionClass.class);
        tlEmergentDictAttentionClass.setUpdateby(uid);
        tlEmergentDictAttentionClass.setUpdatetime(new Date());
        tlEmergentDictAttentionClassMapper.updateById(tlEmergentDictAttentionClass);
        return AjaxResult.success("操作成功");
    }

    @Override
    public AjaxResult deletebyid(JSONObject params) throws HssException {
        String id = params.getString("id");
        tlEmergentDictAttentionClassMapper.deleteById(id);
        return AjaxResult.success("操作成功");
    }

    @Override
    public TlEmergentDictAttentionClass getDetail(JSONObject params) throws HssException {
        String id = params.getString("id");
        TlEmergentDictAttentionClass tlEmergentDictAttentionClass = tlEmergentDictAttentionClassMapper.selectById(id);
        return tlEmergentDictAttentionClass;
    }

    @Override
    public List getSelectList() {
        List resultList = tlEmergentDictAttentionClassMapper.getSelectList();
        return resultList;
    }

//    @Override
//    public JSONObject getList(JSONObject params) throws HssException {
//        Long page = StringUtils.isEmpty(params.getLong("page")) ? 1 : params.getLong("page");
//        Long size = StringUtils.isEmpty(params.getLong("size")) ? 10 : params.getLong("size");
//        JSONObject json = new JSONObject();
//
//        Map<String , Object> map = new HashMap();
//        map.put("operationtypeid" , params.getString("operationtypeid"));
//        map.put("typename" , params.getString("typename"));
//        map.put("status" , params.getString("status"));
//        Page<TlEmergentDictAttentionClass> listPage = new Page<>(page, size, true);
//        IPage<TlEmergentDictAttentionClass> iPage = tlEmergentDictAttentionClassMapper.listTlEmergentDictAttentionClass(listPage, map);
//        json.put("total", iPage.getTotal());
//        json.put("size", iPage.getSize());
//        json.put("pages", iPage.getPages());
//        json.put("current", iPage.getCurrent());
//        json.put("resultlist", iPage.getRecords());
//        return json;
//    }
}
